package cn.forge.mall.framework.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.apache.ibatis.annotations.Mapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;

/**
 * @author liangyuanping
 * @ClassName ForgeMybatisAutoConfiguration
 * @description: 分页插件配置，不增加该配置，会造成分页查询不会去 SELECT COUNT(*)
 * @date 2024年03月20日
 * @version: 1.0
 */
@AutoConfiguration
@MapperScan(value = "${forge.info.base-package}", annotationClass = Mapper.class)
public class ForgeMybatisAutoConfiguration {
    /**
     * 添加分页插件
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor()); // 分页插件
        return mybatisPlusInterceptor;
    }
}
